<?php

abstract class Core_Data_GenericRecord {

    private $Model;
    private $arrValues;
    private $arrUpdateValues;
    private $strPrimaryKey;

    function __construct ( $Model, $arrValues, $strPrimaryKey = null ) {
        $this->Model = $Model;
        $this->arrValues = $arrValues;
        $this->strPrimaryKey = $strPrimaryKey;
    }

    protected function get ( $strField ) {
        if ( array_key_exists( $strField ) ) {
            return $this->arrValues[$strField];
        } else {
            return null;
        }
    }

    protected function set ( $objRecord, $strField, $mixValue, $boolUpdate ) {

        // If $mixValue is neither an integer nor a string, force it into a string.
        if ( !is_integer( $mixValue ) and !is_string( $mixValue ) ) {
            $mixValue = (string) $mixValue;
        }

        // Store the updated value.
        $this->arrUpdateValues[$strField] = $strValue;

        // Do an update.
        if ( $boolUpdate ) {
            // TODO: Temporarily change $arrUpdateValues so that we only update this value.
            $this->Model->update( $objRecord );
        }

    }

    public function getUpdateValues () {
        return $this->arrUpdateValues;
    }

    public function getPrimaryKey () {
        return $this->strPrimaryKey;
    }

    public function getPrimaryKeyValue () {
        if ( $this->getPrimaryKey() ) {
            return $this->arrValues[$this->getPrimaryKey];
        } else {
            return null;
        }
    }

}

?>
